(function(){
	angular.module('app')
	.directive('numCount', countCtrl);
	function countCtrl(){
		return {
			restrict : 'AE',
			scope : {
				numCount : '=',
				countMax :'@countMax',
				countPosition:'@countPosition',
				countTop : '@countTop'
			},
			transclude: true,
			template :'<div class="count-wrap" ng-class="{ \'num-warn\' : warn }" style="{{countPosition}}:0px;top:{{countTop}}px">{{len}}/{{countMax}}</div>',
			link : function( scope, element, attrs){
				scope.len = 0;
				scope.$watch('numCount',function( str ){
					if( str ){
						var length = str.length;
						if(length > scope.countMax){
							str = str.substring(0,scope.countMax);
						}
						length = str.length;
						scope.len = length;
						scope.warn = length > scope.countMax?true : false;
						if( length > scope.countMax ){
							str = '11111';
						}
					}else{
						scope.len = 0;
					}
				});
			}
		}
	}
})();
